const request = require('request');


var getUrl = "http://localhost:8088/getUrl";
var postUrl = "http://localhost:8088/postUrl";
var putUrl = "http://localhost:8088/putUrl";
var deleteUrl = "http://localhost:8088/deleteUrl";

request({
  method: "GET",
  url: "http://localhost:8088/getUrl?name=markix"
}, function (err, resp, body) {
  console.log("get", resp.body);
})
//等价于这个写法，注意url是特殊的单引号，该语法为"模板字符串"
request.get(`${getUrl}`, {
    qs: {
      name: 'markix'
    }
  },
  function (err, resp, body) {
    console.log("get qs", resp.body);
  }
)


//发送请求体，content-type: "application/json"
request.post(`${postUrl}`, {
  body: {
    "name": "markix"
  },
  json: true
}, function (err, resp, body) {
  console.log("post json", resp.body);
})

//发送表单，content-type: "application/x-www-form-urlencoded"
request.post(`${postUrl}`, {
  form: {
    name: 'markix'
  }
}, function (err, resp, body) {
  console.log("post form", resp.body);
});


request.put(`${putUrl}`, {
  body: {
    "name": "markix"
  },
  json: true
}, function (err, resp, body) {
  console.log("put json", resp.body);
})


request.delete(`${deleteUrl}`, {
  body: {
    "name": "markix"
  },
  json: true
}, function (err, resp, body) {
  console.log("delete json", resp.body);
})